/**
 * 
 */
package com.thx.privilege;

import java.util.HashMap;
import java.util.List;

import com.thx.common.spring.BeanFactory;
import com.thx.common.util.ObjectUtils;
import com.thx.privilege.model.PrivilegeType;
import com.thx.privilege.service.PrivilegeTypeManager;
/**
 * @author balance
 * 
 */
public class PriviHandleFactory {

	private static HashMap<String, PriviHandle> handles = null;
	
	public static HashMap<String, PriviHandle> getHandles(){
		if(handles==null){
			synchronized (PriviHandleFactory.class) {
				if(handles==null){
					handles = new HashMap<String, PriviHandle>();
					PrivilegeTypeManager privilegeTypeMgr = (PrivilegeTypeManager) BeanFactory.getBean("privilegeTypeManager");
					List<PrivilegeType> priviTypes = privilegeTypeMgr.getAll();
					if(priviTypes!=null&&priviTypes.size()>0){
						
						for(PrivilegeType pt : priviTypes){
							PriviHandle ph= (PriviHandle) ObjectUtils.getInstance(pt.getHandle());
							handles.put(pt.getTypeKey(), ph);
						}
					}
				}
			}
		}
		
		return handles;
	}
	

}
